<?php

/**
 *json接口
 */
class JsonController extends Controller
{
      //判断是否可以访问该模块
//    public function beforeAction($action)
//    {
//        if(!Yii::app()->user->checkAccess('public'))
//            $this->redirectStay('/login/index','您无权访问');
//        return parent::beforeAction($action);
//    }

    /**
     *接口列表
     */
    public function actionList(){
        $this->left_list_on=4;
        $sql="SELECT count(*) as `cnt` FROM `news_type` $where $page->limit";
        $model=Yii::app()->db->createCommand($sql)->queryAll();
        $cnt=$model[0]['cnt'];
        $page = new Pagination($cnt,$this->page_num);
        $page_list = $page->fpage(array(0,2,3,4,5,6,7,8));
        $sql="SELECT * FROM `news_type` $where ORDER BY id DESC $page->limit";
        $model=Yii::app()->db->createCommand($sql)->queryAll();
        $this->render('admin/news_type_list',array('data'=>$model,'page_list'=>$page_list));
    }
    /**
     *接口新增及修改
     */
    public function actionNewsTypeChange(){
        $this->left_list_on=4;
        $form=$_POST['_form'];
        if($form){
            $id=intval($_POST['id']);
            if($id>0){
                $model=news_type::model()->findByPk($id);
                $model->attributes=$form;
                $model->update();
                $this->redirect('NewsType');
            }else{
                $product_type = new news_type();
                $product_type->attributes = $form;
                $product_type->save();
                $this->redirect('NewsType');
            }
        }
        $id=intval($_GET['id']);
        if($id>0){
            $model=news_type::model()->findByPk($id);
            $data=$model->attributes;
        }
        $this->render('admin/news_type_form',array('data'=>$data));
    }
    /**
     *产品类型ajax删除
     */
    public function actionNewsTypeDel(){
        $id=intval($_POST['id']);
        if($id>0){
            $model = news_type::model()->findByPk($id);
            $model->delete();
        }
        echo 'ok';
    }




}